<section class="books-book">
    <nav class="books-navigation">
        <ul>
            <li class="books-navigation-title<?php echo ($this->article->Id == null & $this->chapter->Id == null ? ' active' : ''); ?>">
                <a href="<?php echo $this->baseUrl(); ?>/book/view/id/<?php echo $this->book->Id; ?>">
                    <img src="<?php echo $this->baseUrl(); ?>/images/icon_book.png" alt="Book" class="books-navigation-icon books-navigation-title-icon" />
                    <span><?php echo $this->book->Title; ?></span>
                </a>
            </li>
            <?php
                $chapters   = $this->book->Chapters;
                if(count($chapters))
                {
                    echo '<ul class="books-navigation-chapters">';
                    foreach($chapters as $chapter)
                    {
                        $active = ($chapter->Id == $this->chapter->Id && $this->article->Id == null) ? true : false;

                        echo '<li'.($active ? ' class="active"' : '').'>'
                                . '<a href="'.$this->baseUrl().'/book/view/id/'.$this->book->Id.'/chapter/'.$chapter->Id.'">'
                                    . '<img src="'.$this->baseUrl().'/images/icon_chapter.png" alt="Chapter" class="books-navigation-icon books-navigation-chapter-icon" />'
                                    . '<span>'.$chapter->Name.'</span>'
                                . '</a>'
                           . '</li>';

                        if($chapter->Id == $this->chapter->Id)
                        {
                            $articles = $chapter->Articles;
                            if(count($articles))
                            {
                                echo '<ul class="books-navigation-articles">';
                                foreach($articles as $article)
                                {
                                    $active = ($article->Id == $this->article->Id) ? true : false;
                                    echo '<li'.($active ? ' class="active"' : '').'>'
                                            . '<a href="'.$this->baseUrl().'/book/view/id/'.$this->book->Id.'/chapter/'.$this->chapter->Id.'/article/'.$article->Id.'">'
                                                . '<img src="'.$this->baseUrl().'/images/icon_article_light.png" alt="Article" class="books-navigation-icon books-navigation-article-icon" />'
                                                . '<span>'.$article->Name.'</span>'
                                            . '</a>'
                                       . '</li>';
                                }
                                echo "</ul>\n";
                            }
                        }
                    }
                    echo "</ul>\n";
                }
            ?>
        </ul>
    </nav>
    
    
    <?php
        if($this->article->Id != null)
        {
    ?>
        <section class="books-book-article">
            <h2><?php echo $this->article->Name; ?></h2>

            <section class="books-book-article-author">
                by 
                <a href="<?php echo $this->baseUrl(); ?>/user/view/id/<?php echo $this->article->Author->Id; ?>">
                    <?php echo $this->article->Author->Fullname; ?>
                </a>
            </section>

            <article class="books-book-article-article">
                <?php echo $this->article->Text; ?>
            </article>

            <section class="books-book-article-date">
                Last revision:
                <?php echo $this->article->ModifiedDate; ?>
            </section>
        </section>
        <section class="books-article-notes">
            <h2>Your notes</h2>

            <section class="books-article-notes-add">
                <div id="notesaddlink">
                    <a href="<?php echo $this->baseUrl(); ?>/note/add/id/<?php echo $this->book->Id; ?>/" id="addnote">+ add a note</a>
                </div>
                <div id="notesform">
                </div>
            </section>

            <section class="books-article-notes-container">
                <div class="feed">
                    <section class="books-article-notes-list list">
                        <?php echo $this->note_partial; ?>
                    </section>
                    <section class="books-article-notes-pager pager">
                        <?php echo $this->note_pager; ?>
                    </section>
                </div>
            </section>
        </section>
    <?php
        }
        else
        if($this->chapter->Id != null)
        {
    ?>
        <section class="books-book-chapter">
            
            <section class="books-book-chapter-book-title">
                <span class="title"><?php echo $this->book->Title; ?></span>
                <span class="subtitle"><?php echo $this->book->Subtitle; ?></span>
            </section>
            
            <h2><?php echo $this->chapter->Name; ?></h2>

            <div class="books-book-chapter-details">
                <section class="books-book-chapter-author">
                    <label>Author</label>
                    <span><a href="<?php echo $this->baseUrl(); ?>/user/view/id/<?php echo $this->chapter->Author->Id; ?>">
                        <?php echo $this->chapter->Author->Fullname; ?>
                    </a></span>
                </section>

                <section class="books-book-chapter-description">
                    <label>Description</label>
                    <span><?php echo $this->chapter->Description; ?></span>
                </section>

                <section class="books-book-chapter-articles">
                    <label>Structure</label>
                    <?php
                        $articles   = $this->chapter->Articles;
                        if(count($articles))
                        {
                            echo '<ul>';
                            foreach($articles as $article)
                            {
                                echo '<li>'
                                        . '<a href="'.$this->baseUrl().'/book/view/id/'.$this->book->Id.'/chapter/'.$this->chapter->Id.'/article/'.$article->Id.'">'
                                            .$article->Name
                                        . '</a>'
                                   . '</li>';
                            }
                            echo '</ul>';
                        }
                    ?>
                </section>
            </div>
        </section>
    <?php
        }
        else
        {
    ?>
        <section class="books-book-summary">
            <section class="books-book-title">
                <span class="title"><?php echo $this->book->Title; ?></span>
                <span class="subtitle"><?php echo $this->book->Subtitle; ?></span>
            </section>
            
            <h2>Book summary</h2>
            
            <section class="books-book-summary-details">
                <section class="books-book-image">
                    <img src="<?php echo $this->baseUrl().'/assets/books/'.$this->book->Image; ?>" class="books-book-image-image" />
                </section>

                

                <section class="books-book-author">
                    <label>Author</label>
                    <span><a href="<?php echo $this->baseUrl(); ?>/user/view/id/<?php echo $this->book->Author->Id; ?>">
                        <?php echo $this->book->Author->Fullname; ?>
                    </a></span>
                </section>

                <section class="books-book-description">
                    <label>Description</label>
                    <span><?php echo $this->book->Description; ?></span>
                </section>

                <section class="books-book-actions">
                    <label>Actions</label>
                    <ul>
                        <?php
                            if(in_array($this->book->Id, $this->user->BookIds))
                            {
                                echo '<li>'
                                        . '<a href="'.$this->baseUrl().'/book/removefromlist/id/'.$this->book->Id.'" onclick="return confirm(\'Are you sure?\');">'
                                            . '<img src="'.$this->baseUrl().'/images/icon_delete.png" alt="Delete" />'
                                            . '<span>Remove from readinglist</span>'
                                        . '</a>'
                                   . '</li>';
                            }
                            else
                            {
                                echo '<li>'
                                        . '<a href="'.$this->baseUrl().'/book/addtolist/id/'.$this->book->Id.'"">'
                                            . '<img src="'.$this->baseUrl().'/images/icon_add.png" alt="Add" />'
                                            . '<span>Add to readinglist</span>'
                                        . '</a>'
                                   . '</li>';
                            }
                        ?>
                    </ul>
                </section>
            </section>
        </section>
        <section class="books-book-reviews">
            <h2>Reviews</h2>

            <section class="books-book-review-add">
                <div id="reviewaddlink">
                    <a href="<?php echo $this->baseUrl(); ?>/review/add/id/<?php echo $this->book->Id; ?>/" id="addreview">+ write a review</a>
                </div>
                <div id="reviewform">
                    
                </div>
            </section>

            <section class="books-book-reviews-container">
                <div class="feed">
                    <section class="books-book-reviews-list list">
                        <?php echo $this->revw_partial; ?>
                    </section>
                    <section class="books-book-reviews-pager pager">
                        <?php echo $this->revw_pager; ?>
                    </section>
                </div>
            </section>

        </section>
    <?php
        }
    ?>
</section>
<input type="hidden" id="book_id" name="book_id" value="<?php echo $this->book->Id;?>" />
<input type="hidden" id="chapter_id" name="chapter_id" value="<?php echo $this->chapter->Id;?>" />
<input type="hidden" id="article_id" name="article_id" value="<?php echo $this->article->Id;?>" />